# coding: utf8
# datetime: 2021-03-22
# 题目地址: https://leetcode-cn.com/problems/number-of-1-bits/


class Solution:
    def hammingWeight(self, n: int) -> int:
        ret = 0
        while n:
            n &= n-1
            ret += 1
        return ret


a = Solution()
print(a.hammingWeight(5))